<template>
	<view class="book-container">
		<view class="book-card" v-for="(item , index) in dataSource" :key="index" @click="toPage(item)">
			<view class="book-header">
				<view class="title-container">
					<view class="book-dept">{{ item.name }}</view>
					<view class="title-bg"></view>
				</view>
				<view v-if="item.status==1">
					<view v-if="changeVisit(item)" class="book-status nobook">已过期</view>
					<view class="book-status" v-else>已预约</view>
				</view>
				<view class="book-status nobook" v-else>已完成</view>
			</view>
			<view class="book-row">
				<view class="label">检查院区 ：</view>
				<view class="value">{{ item.campusName }}</view>
			</view>
			<view class="book-row">
				<view class="label">检查科室 ：</view>
				<view class="value">{{ item.departmentName }}</view>
			</view>
			<view class="book-row">
				<view class="label">检查地址 ：</view>
				<view class="value">{{ item.departmentAddress }}</view>
			</view>
			<view class="book-row" v-if="item.visitNo">
				<view class="label">检查序号 ：</view>
				<view class="value">{{ item.visitNo }}</view>
			</view>
			<view class="book-row">
				<view class="label">医技类型 ：</view>
				<view class="value">{{ item.medicalTypeName }}</view>
			</view>
			<view class="book-row">
				<view class="label">签到时间 ：</view>
				<view class="value">{{ item.visitTime }} {{item.visitArea}}</view>
			</view>
			<view class="book-row">
				<view class="label">预约时间 ：</view>
				<view class="value">{{ item.createTime }}</view>
			</view>
			<view class="book-divider"></view>
			<view class="book-btn-row" v-if="item.status==1">
				<button class="revise-btn" @click.stop="">延迟排队</button>
				<button class="book-btn" @click.stop="">在线签到</button>
			</view>
		</view>
		<u-loadmore :status="status" :icon-type="iconType" :load-text="loadText" @loadmore="loadmore" />
	</view>
</template>

<script>
	import {
		mapGetters
	} from 'vuex'
	import {
		medicalTechnologySelect
	} from '../../../../../api/medicalTechnology';
	import {
		dateFormat
	} from '../../../../../utils/assist';
	export default {
		computed: {
			...mapGetters([
				'userInfo'
			]),
		},
		data() {
			return {
				dataSource: [],
				status: 'loadmore',
				iconType: 'flower',
				loadText: {
					loadmore: '加载更多...',
					loading: '努力加载中',
					nomore: '实在没有了'
				},
				page: 1,
				size: 10,
			}
		},
		mounted() {
			this.init();
		},
		methods: {
			init() {
				medicalTechnologySelect({
					patId: this.userInfo.patId,
					orderBy: 'visit_time desc',
					page: this.page,
					size: this.size
				}).then(res => {
					if (res.length == 0) {
						this.status = 'nomore'
					} else {
						this.status = 'loadmore'
						this.dataSource = [...this.dataSource, ...res];
					}
				})
			},
			loadmore() {
				this.page = this.page + 1
				this.init();
			},
			toPage(item) {

				uni.navigateTo({
					url: '/pages/Home/ServePatient/MedicalTechnologyEdit?item=' + JSON.stringify(item)
				})
			},
			changeVisit(e) {
				console.log(e)
				let visit = new Date(e.visitTime);
				let date = new Date(dateFormat("yyyy-MM-dd", new Date()));
				console.log(visit.getTime(), date.getTime())
				if (visit.getTime() < date.getTime()) {
					return true
				} else {
					return false
				}

			}
		}
	}
</script>

<style lang="scss" scoped>
	.book-card {
		background: #fff;
		border-radius: 16rpx;
		margin: 25rpx 0 0 0;
		box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.08);
		padding: 24rpx 32rpx 18rpx 32rpx;
	}

	.book-header {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-bottom: 18rpx;
	}

	.title-container {
		position: relative;
	}

	.book-dept {
		font-size: 32rpx;
		color: #333;
		font-weight: bold;
	}

	.title-bg {
		position: absolute;
		width: 48rpx;
		height: 15rpx;
		background-color: rgba(65, 207, 230, 0.5);
		bottom: 0;
		left: calc(20%);
		z-index: 0
	}

	.book-status {
		background: #4ad49a;
		color: #fff;
		border-radius: 8px;
		padding: 4px 18px;
		right: 8px;
		width: 90px;
		text-align: center;
		white-space: nowrap;
	}

	.book-status.nobook {
		background: #394e53;
	}

	.book-divider {
		height: 1rpx;
		border-top: 1rpx dashed #e0e0e0;
		margin: 18rpx 0 18rpx 0;
		width: 100%;
	}

	.book-row {
		display: flex;
		align-items: center;
		margin-bottom: 16rpx;
	}

	.label {
		color: #888;
		font-size: 28rpx;
		width: 160rpx;
	}

	.value {
		font-size: 28rpx;
		flex: 1;
	}

	.desc {
		color: #ca3333;
		font-size: 28rpx;
		flex: 1;
	}

	.nav-btn {
		background: #e0f3ff;
		color: #1ec6e6;
		font-size: 22rpx;
		border-radius: 24rpx;
		padding: 0 18rpx;
		height: 40rpx;
		line-height: 40rpx;
		border: none;
		margin-left: 12rpx;
	}

	.book-btn-row {
		display: flex;
		justify-content: space-between;
		margin: 30rpx 0 15rpx;
	}

	.revise-btn {
		width: 48%;
		height: 64rpx;
		background: #fff;
		color: #1ec6e6;
		font-size: 28rpx;
		border-radius: 44rpx;
		border: 1rpx solid #1ec6e6;
		text-align: center;
		line-height: 64rpx;
	}

	.book-btn {
		width: 48%;
		height: 64rpx;
		background: linear-gradient(90deg, #6ed6f7 0%, #3ec6e7 100%);
		color: #fff;
		font-size: 28rpx;
		border-radius: 44rpx;
		text-align: center;
		line-height: 64rpx;
		border: none;
	}
</style>